package com.jsmile.cloud.taskcenter.task.quartz;

import java.util.Map;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.jsmile.cloud.taskcenter.api.constants.TaskConstants;
import com.jsmile.cloud.taskcenter.task.kit.TaskKit;
import com.jsmile.cloud.taskcenter.task.model.TaskModel;

/**
 * 有状态任务
 *
 * @author 龚亮
 * @description 若一个方法一次执行不完下次轮转时则等待改方法执行完后才执行下一次操作
 * @date 2015-05-27 14:22:13
 */
@DisallowConcurrentExecution
public class QuartzJobFactoryDisallowConcurrentExecution implements Job {

    @Override
    @SuppressWarnings("unchecked")
    public void execute(JobExecutionContext context) throws JobExecutionException {
        TaskModel scheduleJob = (TaskModel)context.getMergedJobDataMap().get(TaskConstants.TASK.SCHEDULE_JOB);
        Map<String, Object> data = (Map<String, Object>)context.getMergedJobDataMap().get(TaskConstants.TASK.JOB_DATA_MAP);
        TaskKit.invokMethod(scheduleJob, data);
    }

}
